import logging

from config import BASE_URL


class RechargeApi:

    def __init__(self,session):
        self.session = session
    # 接收session对象的变量

    # 获取充值验证码接口
    def get_recharge_verify_code(self,r):
        url = BASE_URL + f'/common/public/verifycode/{r}'
        resp = self.session.get(url)
        logging.info(f'获取充值验证码 = {resp}')
        return resp

    # 充值接口
    def recharge(self,amount_v,valicode_v,formStr_v="reForm",paymentType_v="chinapnrTrust"):
        # 定义一个字典变量，用来接收请求体数据
        url = BASE_URL + '/trust/trust/recharge'
        info = {"paymentType": paymentType_v, "amount": amount_v, "formStr":formStr_v , "valicode": valicode_v}
        resp = self.session.post(url,data=info)
        print(f'充值接口响应体数据 = {resp.json()}')
        logging.info(f'充值接口响应体数据 = {resp.json()}')
        return resp

    # 第三方充值接口
    def third_recharge(self,url,body):
        resp = self.session.post(url,data=body)
        print(f'第三方充值接口响应数据 = {resp.text}')
        logging.info(f'第三方充值接口响应数据 = {resp.text}')
        return resp
